var app = getApp(),
  $ = require("../../utils/httpHelper.js");
var address = require('../../utils/city.js')

Page({
  data: {
    height: 0,
    balance:0.00,
    banklist: [{ name: '高新二路店', id: 1 }, { name: '高新三路店', id: 2 }],//银行对象
    bankitem:[],//银行名字
    bankindex:[],//银行编号
    bankno:'',//选中银行编号
    index:0,//选择银行数组的index
    paymoney:''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        that.setData({ height: res.windowHeight })
      }
    })
    let par = {
      rd_session: app.globalData.userInfo.rd_session
    }
    // $.httpPost("member_info", par, (data, err) => {
    //   this.setData({
    //     balance: data.data.data.balance
    //   })
    // })
    $.httpPost("mendian_list", par, (data, err) => {
      let name = []
      let indexa = []
      for (let item of data.list){
        name.push(item.name)
        indexa.push(item.id)
      }
      this.setData({
        banklist: data.list,
        bankname:name,
        bankindex:indexa,
        bankno: data.list[this.data.index].id
      })
    })
  },

  bindKeyInput: function (e) {
    this.setData({
      paymoney: e.detail.value
    })
  },
  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    let banknos = this.data.bankindex
    console.log(banknos)
    this.setData({
      bankno: banknos[e.detail.value],
      index: e.detail.value
    })
    console.log(this.data.bankno)
  },
  selectbank(){

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  topay(){
    console.log(this.data.bankno)
    if (!app.check_empty(this.data.paymoney)){
      let par = {
        rd_session: app.globalData.userInfo.rd_session,
        mendian_id: this.data.bankno,
        total_fee: this.data.paymoney,
        openid: app.globalData.userInfo.openId
      }
      $.httpPost("build_payorderparam", par, (data, err) => {
        let that = this
        if (data.result == 'success') {
          app.wxPays({
            data,
            success: function () {
              wx.showToast({
                title: '支付成功哈',
              })
              that.setData({
                paymoney:''
              })
            },
            fail: function () {
              wx.showToast({
                title: '支付失败了呢',
              })
            }
          })
        }
      })
    }else{
      wx.showToast({
        title: '不能是空',
      })
    }
    
  },
  phone1: function () {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: "17782833823"
    })
  },
})
